<html>
<head><meta charset="utf-8"><title>Removing ptr::Unique? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Removing.20ptr.3A.3AUnique.3F.html">Removing ptr::Unique?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244018233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Removing%20ptr%3A%3AUnique%3F/near/244018233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> fee1-dead <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Removing.20ptr.3A.3AUnique.3F.html#244018233">(Jun 26 2021 at 14:41)</a>:</h4>
<p>If it can be replaced by <code>NonNull</code>, <code>PhantomData</code>, <code>Send</code> and <code>Sync</code>, why not remove it entirely?<br>
There is no point having it and the rustonomicon is confusing (<a href="https://doc.rust-lang.org/nomicon/vec-layout.html#layout">suggests</a> using <code>Unique</code> and says null pointer optimization cannot be achieved in stable Rust)</p>
<p>All the usages of <code>Unique</code> can be easily replaced. It doesn't justify existing as "internal" when all it does is to save one from manually implementing <code>Send</code> and <code>Sync</code>.</p>



<a name="244018489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Removing%20ptr%3A%3AUnique%3F/near/244018489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Removing.20ptr.3A.3AUnique.3F.html#244018489">(Jun 26 2021 at 14:46)</a>:</h4>
<p>Doesn't Unique provide no_alias metadata to llvm which mut pointers don't?</p>



<a name="244018687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Removing%20ptr%3A%3AUnique%3F/near/244018687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> fee1-dead <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Removing.20ptr.3A.3AUnique.3F.html#244018687">(Jun 26 2021 at 14:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="330154">The 8472</span> <a href="#narrow/stream/122651-general/topic/Removing.20ptr.3A.3AUnique.3F/near/244018489">said</a>:</p>
<blockquote>
<p>Doesn't Unique provide no_alias metadata to llvm which mut pointers don't?</p>
</blockquote>
<p>Well, do <code>NonNull</code> pointers not enable this optimization?</p>



<a name="244020271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Removing%20ptr%3A%3AUnique%3F/near/244020271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Removing.20ptr.3A.3AUnique.3F.html#244020271">(Jun 26 2021 at 15:26)</a>:</h4>
<p>no</p>



<a name="244020464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Removing%20ptr%3A%3AUnique%3F/near/244020464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Giacomo Stevanato <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Removing.20ptr.3A.3AUnique.3F.html#244020464">(Jun 26 2021 at 15:31)</a>:</h4>
<p>Just wondering, how does <code>Unique</code> provide no_alias informations? It doesn't appear to be a lang item</p>



<a name="244021899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Removing%20ptr%3A%3AUnique%3F/near/244021899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> fee1-dead <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Removing.20ptr.3A.3AUnique.3F.html#244021899">(Jun 26 2021 at 16:02)</a>:</h4>
<p><span class="user-mention silent" data-user-id="330154">The 8472</span> <a href="#narrow/stream/122651-general/topic/Removing.20ptr.3A.3AUnique.3F/near/244018489">said</a>:</p>
<blockquote>
<p>Doesn't Unique provide no_alias metadata to llvm which mut pointers don't?</p>
</blockquote>
<p>I checked and it looks like the metadata is only enabled for <code>Box</code>.</p>
<p><a href="https://github.com/rust-lang/rust/blob/831ae3c1364b7b033bd1da430bc1cb86d93ad186/compiler/rustc_middle/src/ty/layout.rs#L2429-L2436">https://github.com/rust-lang/rust/blob/831ae3c1364b7b033bd1da430bc1cb86d93ad186/compiler/rustc_middle/src/ty/layout.rs#L2429-L2436</a>:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">                </span><span class="c1">// FIXME(eddyb) This should be for `ptr::Unique&lt;T&gt;`, not `Box&lt;T&gt;`.</span>
<span class="w">                </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="k">ref</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">pointee</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">result</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                    </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">ty</span>::<span class="n">Adt</span><span class="p">(</span><span class="n">def</span><span class="p">,</span><span class="w"> </span><span class="n">_</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">this</span><span class="p">.</span><span class="n">ty</span><span class="p">.</span><span class="n">kind</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                        </span><span class="k">if</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">is_box</span><span class="p">()</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="n">offset</span><span class="p">.</span><span class="n">bytes</span><span class="p">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                            </span><span class="n">pointee</span><span class="p">.</span><span class="n">safe</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">PointerKind</span>::<span class="n">UniqueOwned</span><span class="p">);</span><span class="w"></span>
<span class="w">                        </span><span class="p">}</span><span class="w"></span>
<span class="w">                    </span><span class="p">}</span><span class="w"></span>
<span class="w">                </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="244023414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Removing%20ptr%3A%3AUnique%3F/near/244023414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Removing.20ptr.3A.3AUnique.3F.html#244023414">(Jun 26 2021 at 16:39)</a>:</h4>
<p>previous discussion <a href="https://github.com/rust-lang/rust/issues/71530">#71530</a></p>



<a name="245009580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Removing%20ptr%3A%3AUnique%3F/near/245009580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Removing.20ptr.3A.3AUnique.3F.html#245009580">(Jul 06 2021 at 08:35)</a>:</h4>
<p><span class="user-mention silent" data-user-id="338379">Giacomo Stevanato</span> <a href="#narrow/stream/122651-general/topic/Removing.20ptr.3A.3AUnique.3F/near/244020464">said</a>:</p>
<blockquote>
<p>Just wondering, how does <code>Unique</code> provide no_alias informations? It doesn't appear to be a lang item</p>
</blockquote>
<p>it doesn't currently, but is planned to in the future, once we know what exactly the rules are^^</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>